package com.example.springboot.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.springboot.service.PublishMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: VoteServerApi
 * @Author wenlinyu
 * @Date: 2020/12/21 14:27
 * @Version 1.0
 */
@RestController
@RequestMapping("/vote")
public class VoteServerApi {

    @Autowired
    private PublishMessage publishMessage;

    /**
     * 提交投票
     * @param voteId
     * @param message
     * @return
     */
    @RequestMapping("/save")
    public String save(String voteId, String message) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("voteId", voteId);
        jsonObject.put("message", message);
        // 业务数据入库...省略
        // 将消息发布到redis
        publishMessage.publishTopicMessage(jsonObject);
        return "提交成功";
    }
}
